package com.nagarro.inventory;

/**
 * Represents imported items. Extends Item.
 * Final Cost for imported item includes
 * 12.5% tax, 10% import duty and a surcharge amount
 * @author uditverma
 *
 */
public class ImportedItem extends Item {

	private static final float IMPORT_DUTY = .1f; // 10% Import Duty
	private static final float SURCHARGE_PERCENTAGE = .05f; // 5% Surcharge Percentage
	private static final int SURCHARGE_LOWER_LIMIT = 100;
	private static final int SURCHARGE_UPPER_LIMIT = 200;
		
	/*
	 * Calculate final price by applying 12.5% tax, 10% import duty and
	 * surcharge
	 */
	@Override
	public double getTotal(int quantity) {
		double cost = this.getCost(quantity);
		cost = cost + this.getTax(cost);
		cost = cost + getImportDuty(cost);
		cost = cost + getSurcharge(cost);
		/* Calculate Tax */
		this.setTax(cost - this.getCost(quantity));
		return cost;
	}

	/**
	 * calculate the import duty
	 * @param cost cost after applying taxes
	 * @return import duty to be added
	 */
	private double getImportDuty(final double cost) {
		return cost * IMPORT_DUTY;
	}

	/**
	 * calculate the surcharge
	 * @param cost cost after applying taxes and import duty
	 * @return surcharge to be added
	 */
	private double getSurcharge(final double cost) {
		if (cost <= SURCHARGE_LOWER_LIMIT) {
			/* If Cost is less than equal to 100, apply a surcharge of 5 */
			return 5;
		} else if ((cost > SURCHARGE_LOWER_LIMIT) && (cost <= SURCHARGE_UPPER_LIMIT)) {
			/* If Cost is between 100-200, apply a surcharge of 10 */
			return 10;
		} else {
			/*
			 * If Cost is more than 200, apply a surcharge of
			 * SURCHARGE_PERCENTAGE
			 */
			return cost * SURCHARGE_PERCENTAGE;
		}
	}
}
